﻿using UnityEngine;
using System.Collections;

public class skärpänen : MonoBehaviour
{
	private float useSpeed;
	public float directionSpeed = 5.0f;
	float origX;
	public float distance = 2.0f;
	
	// Use this for initialization
	void Start () 
	{
		origX = transform.position.x;
		useSpeed = -directionSpeed;
	}
	
	// Update is called once per frame
	void Update ()
	{
		if(origX - transform.position.x > distance)
		{
			useSpeed = directionSpeed; //flip direction
		}
		else if(origX - transform.position.x < -distance)
		{
			useSpeed = -directionSpeed; //flip direction
		}
		transform.Translate(Mathf.Sin (Time.time)/15,Mathf.Cos (Time.time)/10,1 );
	}
	
}